package com.party.controller;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;

public class QRCodeGenerator {
    private static final int QR_CODE_SIZE = 200; // 二维码的宽高，以像素为单位

    public static void main(String[] args) throws WriterException, IOException {

        String textToEncode = "Hello, World!"; // 待编码的文本
        Path imagePath = FileSystems.getDefault().getPath("qrcode.png"); // 生成的二维码图片路径
        System.out.println(imagePath);
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        BitMatrix bitMatrix = qrCodeWriter.encode(textToEncode, BarcodeFormat.QR_CODE, QR_CODE_SIZE, QR_CODE_SIZE);
        MatrixToImageWriter.writeToPath(bitMatrix, "PNG", imagePath);
    }
}
